<div class="layui-fluid" id="VIEW-list-table" lay-title="分配客户">
    <div class="layui-row">
        <div>未分配客户数：<span id="unconfirmedCustomerCount">0</span></div>
    </div>
    <div class="layui-row">
        <table lay-filter="lig-salesQuantity-table"></table>
    </div>
    <div>
        <div class="ligui-layer-btn" style="text-align:right;pointer-events:auto;">
            <a class="ligui-layer-btn0 ligui-choose" lay-filter="lig-salesQuantity-ok">确 定</a>
            <a class="ligui-layer-btn1 ligui-cancel" lay-filter="lig-salesQuantity-cancel">取 消</a>
        </div>
    </div>
</div>

<script>
    layui.use(['admin', 'table', 'form', 'dropdown', 'laytpl', 'jquery','lig'], function (admin, table, form, dropdown, laytpl, $, lig) {
        var init = function() {
            lig.ajaxget({
                url: 'bu/customer/getUnconfirmedCustomerCount',
                success: function(res) {
                    $('#unconfirmedCustomerCount').text(res.data);
                }
            });
        }


        init();
        form.render();

        lig.table({
            elem: '[lay-filter="lig-salesQuantity-table"]',
            url: 'bu/customer/querySalesQuantity',
            cols: [[
                { title: '', type: 'checkbox', fixed: true, width: 60 },
                { title: '业务员', field: 'salesName', width: '30%' },
                { title: '已分配', field: 'customerCount', width: '20%' },
                { title: '本次分配', field: 'quantity', edit: 'text', width: '30%' }

            ]],
            page: false
        },{
            entity: 'salesQuantity',
            primaryField: 'id'
        });

        $('[lay-filter="lig-salesQuantity-ok"]').click(function () {
            var datas = table.getData('salesQuantityId');
            if (datas.length <= 0) {
                return;
            }

            var data = [];
            $.each(datas, function(i, it) {
                data.push({salesId: it.salesId, quantity: it.quantity});
            });
            parent.salesQuantity_dataJson = data;
            layer.close(layer.index);
        });
        $('[lay-filter="lig-salesQuantity-cancel"]').click(function () {
            layer.close(layer.index);
        });
    })
</script>